package com.fengjing.launcher.parse;

import android.util.Log;

import com.fengjing.launcher.model.FeiChangYingYuan;
import com.fengjing.launcher.model.FilmModel;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2017/9/21.
 */

public class FeiChangYingYuanParser {
    private static final String TAG = "FeiChangYingYuanParser";

    public static void getFenLeiList(List<FeiChangYingYuan> feiChangYingYuans) {
        File file = new File(AdParser.getFeiChangPath());

        if (!file.exists()) {
            Log.e(TAG, file.getAbsolutePath() + "路径不存在！！");
            return;
        }

        File[] files = file.listFiles();

        for (int i = 0; i < files.length; i++) {
            if (i > feiChangYingYuans.size() - 1) {
                FeiChangYingYuan feiChangYingYuan = new FeiChangYingYuan();
                feiChangYingYuans.add(feiChangYingYuan);
            }
            feiChangYingYuans.get(i).setFenLeiName(files[i].getName());
            feiChangYingYuans.get(i).setFenLeiAliasName(AdParser.switchName(files[i].getName()));
        }
    }

    public static void getFenLeiXiangQing(FeiChangYingYuan feiChangYingYuan) {

        String fenLeiName = feiChangYingYuan.getFenLeiName();

        File file = new File(AdParser.getFeiChangPath() + File.separator + fenLeiName);

        if (!file.exists()) {
            Log.e(TAG, file.getAbsolutePath() + "路径不存在！！");
            return;
        }

        List<FilmModel> filmModels = new ArrayList<>();

        boolean isVR = false, is3D = false, isEpisode = false;

        if (fenLeiName.matches(".*3D.*")) {
            is3D = true;
        }

        if (fenLeiName.matches("(.*jj.*)||(.*zy.*)")) {
            isEpisode = true;
        }

        if (fenLeiName.matches(".*[V|v][R|r].*")) {
            isVR = true;
        }

        FilmParser.getFilmList(file.getPath(), filmModels, isVR, is3D, isEpisode);

        feiChangYingYuan.setFilmList(filmModels);
    }


}
